home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
Libraries
/
SAT 2.3b4
/
Demo ƒ
/
Collision][ demo ƒ
/
sApple.c
< prev
next >
Wrap
Text File
|
1995-01-16
|
2KB
|
88 lines
/* Apple sprite for SATcollision][ */
/* No, it has nothing to do with old Apple computers :-) */
/* unit sApple; */
#include "SAT.h"
#include "Collision][.h"
static Handle nammSound, bliaehSound;
static FacePtr goodFace, badFace;
static FacePtr coreDump;
void InitApple()
{
int i;
nammSound = SATGetNamedSound("\pnamm");
bliaehSound = SATGetNamedSound("\pbliaeh");
goodFace = SATGetFace(132);
badFace = SATGetFace(133);
coreDump = SATGetFace(135);
}
pascal void SetupApple (SpritePtr me)
{
me->speed.h = 1 + SATRand(3);
me->kind = -2; /*Enemy kind*/
me->face = goodFace;
SetRect(&me->hotRect, 0, 0, 32, 32);
me->task = HandleApple;
me->hitTask = HitApple;
}
/*We use kind -2 for fresh apples and kind -3 for bad apples. We avoid -1, since it doesn't count for the "anymonsters" flag.*/
/*Note that the "kind" field is not modified my SAT since we are not using KindCollision!*/
pascal void HandleApple (SpritePtr me)
{
switch (me->kind) {
case -2:
me->face = goodFace;
break;
case -3:
me->face = badFace;
break;
}; /*switch*/
me->position.h = me->position.h + me->speed.h;
if (me->position.h > gSAT.offSizeH - 16)
{
me->speed.h = -1 - SATRand(3);
if (SATRand(2) == 0)
me->kind = -3;
else
me->kind = -2;
};
if (me->position.h < -16)
{
me->speed.h = 1 + SATRand(3);
if (SATRand(2) == 0)
me->kind = -3;
else
me->kind = -2;
};
}
pascal void HitApple(SpritePtr me, SpritePtr him)
{
if (him->task == &HandleApple)
me->kind = -3; /*Colliding apples corrupt each other!*/
else
/*If "him" is not an apple, then it must be the player!*/
if (him->mode >= 0) /*if the player feels bad, don't eat*/
switch (me->kind) {
case -2:
SATSoundPlay(nammSound, 1, false);
me->task = nil;
him->mode = 25;
SATPlotFace(coreDump, nil, me->position, true);
break;
case -3: /*Bad apple, make player feel bad.*/
him->mode = -20;
SATSoundPlay(bliaehSound, 2, false);
break;
};
}